home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.input;
-
- import sub_arctic.lib.interactor;
- import sub_arctic.lib.sub_arctic_error;
-
- import java.util.Vector;
-
- /**
- * This is the abstract base class for all focus dispatch agents. It provides
- * infrastructure for maintaining objects in focus sets, notifying objects of
- * entry and exit from the focus set, etc. This (partial) agent dispatches
- * input under the focusable input protocol.<p>
- *
- * @see sub_arctic.input.focusable
- * @author Scott Hudson
- */
- public abstract class focus_dispatch_agent extends dispatch_agent {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* Default constructor. This creates an empty focus set to start with. */
- public focus_dispatch_agent()
- {
- _focus_set = new Vector();
- _user_info_set = new Vector();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Focus set. This contains focusable objects and maintains all objects
- * that are currently in the focus set for this agent. This list is
- * maintained in synch with _user_info_set which contains the user info
- * objects belonging to each object in the focus set.
- */
- protected Vector _focus_set;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Each focus object may provide a user info object when it is placed in
- * the focus set. This vector maintains the set of those objects
- * corresponding the interactor objects in the current focus set. Positions
- * in this vector correspond directly to positions in _focus_set. This
- * vector contains objects of any type.
- */
- protected Vector _user_info_set;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Indicate the size of the current focus set. */
- public int focus_set_size() {return _focus_set.size();}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the focus object at a given index in the focus set vector.
- * @param int at_indx the index of the requested object.
- * @returns focusable the object at that index.
- */
- public focusable focus_item(int at_indx) {
- if (at_indx < 0 || at_indx >= _focus_set.size()) {
- throw new sub_arctic_error("Request for focus set item out of range");
- }
- return (focusable)_focus_set.elementAt(at_indx);
- }
-
- //had:
- //* @exception index_bounds if the index is out of range.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Retrieve the user info object corresponding to the focusable object at
- * the given index.
- * @param int at_indx the index of the requested object.
- * @returns Object user info for the object at that index.
- */
- protected Object user_info_item(int at_indx) {
- if (at_indx < 0 || at_indx >= _focus_set.size())
- throw new sub_arctic_error("Request for user info set item out of range");
- return _user_info_set.elementAt(at_indx);
- }
-
- //had:
- //* @exception index_bounds if the index is out of range.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method is called whenever an object enters the focus set. It
- * calls focus_set_enter() on the object (as part of the focusable input
- * protocol). Note: in some subclass agents, the focus_set_enter() call
- * is replaced by a more specific call particular to the protocol managed
- * by that agent. <p>
- *
- * @param focusable obj the object entering the focus set.
- * @param event evt the event that "caused" the entry.
- * @param Object user_info the user info associated with that object.
- */
- protected void inform_focus_enter(
- focusable obj,
- event evt,
- Object user_info) {
- /* dispatch it */
- obj.focus_set_enter(evt,this,user_info);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method is called whenever an object exits the focus set. It
- * calls focus_set_exit() on the object (as part of the focusable input
- * protocol). Note: in some subclass agents, the focus_set_exit() call
- * is replaced by a more specific call particular to the protocol managed
- * by that agent. <p>
- *
- * @param focusable obj the object exiting the focus set.
- * @param event evt the event that "caused" the exit.
- * @param Object user_info the user info associated with that object.
- */
- protected void inform_focus_exit(
- focusable obj,
- event evt,
- Object user_info) {
- /* dispatch it */
- obj.focus_set_exit(evt,this,user_info);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Do subclass specific test to see if the given object is eligible to
- * go in the focus set. Typically we would test that the object implements
- * the interface that defines the input dispatch protocol in question.
- * Here in the superclass we let anything in.<p>
- *
- * @param focusable candidate_obj object we are accepting or rejecting
- * @return boolean indicating if the object is suitable for inclusion in the
- * focus set.
- */
- public boolean allowable_focus(focusable candidate_obj) {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Replace the focus set of this agent with the given object. This provides
- * a causal event and an uninterpreted object that will be passed back to
- * the focus object whenever input is delivered to it by this agent.<p>
- *
- * @param focusable to_obj the object going in the focus set.
- * @param event evt the event that "caused" this focus.
- * @param Object user_info the uninterpreted information that we will pass
- * back to the object whenever it gets input from
- * this agent.
- */
- public void set_focus_to(focusable to_obj, event evt, Object user_info) {
- int i;
- focusable remove_obj;
- Object remove_info;
- boolean already_focus = false;
-
- /* make sure its ok to add */
- if (!allowable_focus(to_obj))
- throw new sub_arctic_error("Attempt to add an ineligible object to the focus set");
-
- /* if they set to a null focus, treat that as a clear */
- if (to_obj == null)
- {
- clear_focus(evt);
- return;
- }
-
- /* inform all the old focus objects that they have lost focus */
- for (i = 0; i < _focus_set.size(); i++)
- {
- remove_obj = (focusable)_focus_set.elementAt(i);
- remove_info = _user_info_set.elementAt(i);
-
- /* but don't inform the object we are about to put in... */
- if (to_obj != remove_obj)
- inform_focus_exit(remove_obj,evt,remove_info);
- else
- already_focus = true;
- }
-
- /* dump the old set and start over */
- _focus_set = new Vector();
- _focus_set.addElement(to_obj);
- _user_info_set = new Vector();
- _user_info_set.addElement(user_info);
-
- /* if we are just entering, inform the object */
- if (!already_focus)
- inform_focus_enter(to_obj,evt,user_info);
- }
-
- //had:
- //* @exception bad_value if this object is not suitable for inclusion in this
- //* focus set.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Determine if the given object is currently part of the focus set for this
- * agent.<p>
- *
- * @param focusable obj the object we are asking about
- * @return boolean indicating whether the object is in the focus set.
- */
- public boolean is_in_focus(focusable obj)
- {
- int indx;
-
- /* look for the object in the focus set */
- indx = _focus_set.indexOf(obj);
-
- /* -1 indicates not there */
- return indx >= 0;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Add an object to the focus set of this agent. This provides
- * a causal event and an uninterpreted object that will be passed back to
- * the focus object whenever input is delivered to it by this agent.<p>
- *
- * @param focusable to_obj the object going in the focus set.
- * @param event evt the event that "caused" this focus.
- * @param Object user_info the uninterpreted information that we will pass
- * back to the object whenever it gets input from
- * this agent.
- */
- public void add_to_focus(focusable new_obj, event evt, Object user_info)
- {
- /* make sure its ok to add */
- if (!allowable_focus(new_obj))
- throw new sub_arctic_error(
- "Attempt to add an ineligible object to the focus set");
-
- /* don't do anything if we are already in the focus set */
- if (!is_in_focus(new_obj))
- {
- /* add it to the focus set and let it know its been added */
- _focus_set.addElement(new_obj);
- _user_info_set.addElement(user_info);
- inform_focus_enter(new_obj, evt, user_info);
- }
- }
-
- //had:
- //* @exception bad_value if this object is not suitable for inclusion in this
- //* focus set.
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Remove the given object from the focus set of this agent.
- * @param focusable obj the object to be removed.
- * @param event evt the event that "caused" this removal.
- */
- public void remove_from_focus(focusable obj, event evt)
- {
- int indx;
- Object user_info;
-
- /* find the object */
- indx = _focus_set.indexOf(obj);
-
- /* if its not there, throw an exception */
- if (indx < 0)
- throw new sub_arctic_error(
- "Attempt to remove focus from an object not in the focus set");
-
- /* otherwise remove it and let it know */
- _focus_set.removeElementAt(indx);
- user_info = _user_info_set.elementAt(indx);
- _user_info_set.removeElementAt(indx);
- inform_focus_exit(obj, evt, user_info);
- }
-
- //had:
- //* @exception bad_value if this object is not not in the focus set.
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Clear the focus set of this agent to empty.
- * @param event evt the event that "caused" this.
- */
- public void clear_focus(event evt)
- {
- int i;
- focusable remove_obj;
- Object remove_info;
-
- /* inform all the old focus objects that they have lost focus */
- for (i = 0; i < _focus_set.size(); i++)
- {
- remove_obj = (focusable)_focus_set.elementAt(i);
- remove_info = _user_info_set.elementAt(i);
- inform_focus_exit(remove_obj,evt,remove_info);
- }
-
- /* dump the old set and start over */
- _focus_set = new Vector();
- }
-
- //has:
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Attempt to dispatch an event to an object or set of objects via this
- * agent. The event is passed in all cases. In our case (for focus agents),
- * the remaining parameters are ignored as we store the user_info and
- * object to dispatch to internally, and are not passed the same event
- * more than once. This method is overridden by each subclass to do its
- * specific work. <p>
- *
- * @param event evt the event to be dispatched.
- * @param Object user_info ignored.
- * @param interactor to_obj ignored.
- * @param int seq_num ignored.
- */
- public abstract boolean dispatch_event(
- event evt,
- Object user_info,
- interactor to_obj,
- int seq_num) ;
-
- //had:
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-